package org.yzz.org.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.yzz.base.service.impl.BaseServiceImpl;
import org.yzz.org.domain.Employee;
import org.yzz.org.dto.EmployeeDTO;
import org.yzz.org.mapper.EmployeeMapper;
import org.yzz.org.service.IEmployeeService;

import java.util.List;
import java.util.Objects;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements IEmployeeService {
    @Autowired
    private EmployeeMapper mapper;

    @Override
    public Employee selectByName(String username) {
        return mapper.selectByName(username);
    }

    @Override
    @Transactional
    public void insertByRoleId(EmployeeDTO employeeDTO) {
        mapper.deleteByRoleId(employeeDTO.getId());
        if(Objects.isNull(employeeDTO.getRoleIds()) || employeeDTO.getRoleIds().size()==0) return;
        mapper.insertByRoleId(employeeDTO);
    }

    @Override
    public List<Long> selectRoleById(Long id) {
        return mapper.selectRoleById(id);
    }

    @Override
    public List<String> queryPermissionByUserId(Long id) {
        return mapper.queryPermissionByUserId(id);
    }
}
